package com.huakang.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huakang.entity.Prescription;
import com.huakang.service.PrescriptionService;
import com.huakang.utils.PrescriptionVo;
import com.huakang.utils.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author{一只小呆瓜}
 * @Date2025/1/11 20:16
 */
@RestController
@RequestMapping(value = "/prescription")
public class PrescriptionController {
    @Autowired
    private PrescriptionService prescriptionService;
    @GetMapping(value = "/findAll")
    public ResultVo findname(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<PrescriptionVo> prescriptionList = prescriptionService.findname();
        PageInfo<PrescriptionVo> pageInfo = new PageInfo<>(prescriptionList);
        return ResultVo.success("查询成功",pageInfo);
    }
    @PostMapping(value = "/add")
    public ResultVo add(@RequestBody PrescriptionVo prescription){
        boolean flag = prescriptionService.add(prescription);
        if (flag){
            return ResultVo.success("添加成功");
        }else {
            return ResultVo.fail("添加失败");
        }

    }
    @PostMapping(value = "/addchufang")
    public ResultVo addchufang(@RequestBody Prescription prescription){
        boolean flag = prescriptionService.addchufang(prescription);
        if (flag){
            return ResultVo.success("添加成功");
        }else {
            return ResultVo.fail("添加失败");
        }

    }
    @GetMapping("/findPid")
    public ResultVo findPid(Integer pid){
        List<PrescriptionVo> prescriptionList = prescriptionService.findPid(pid);
        return ResultVo.success("查询成功",prescriptionList);
    }
    @PostMapping("/update")
    public  ResultVo update(@RequestBody Prescription prescription){
        boolean b=prescriptionService.update(prescription);
        if(b){
            return  ResultVo.success("修改成功");
        }
        return  ResultVo.fail("修改失败");
    }
}
